#include "promenieditor.h"
#include "ui_promenieditor.h"
#include <QCheckBox>

PromeniEditor::PromeniEditor(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PromeniEditor)
{
    ui->setupUi(this);
}

//QSize PromeniEditor::sizeHint()
//{
//    return this->sizeHint();
//}

PromeniEditor::~PromeniEditor()
{
    delete ui;
}

void PromeniEditor::setPromeni(const QString &promeni)
{
    if (promeni.isEmpty()) return;
    QStringList promeniList ( promeni.split(",") );

    foreach (QString s, promeniList) {
        QCheckBox *cb = findChild<QCheckBox*>(QString("cb%1").arg(s));
        if (cb!=NULL)
        {
            cb->setChecked( true );
        }
    }
}

QString PromeniEditor::getPromeni() const
{
    QString promeni;
    QList<QCheckBox*> cbList = findChildren<QCheckBox*>();
    foreach (QCheckBox* cb, cbList) {
        if (cb!=NULL)
            if (cb->isChecked())
            {
                QString number = cb->objectName().right(1); // WARN: only for 0..9
                promeni.append( promeni.isEmpty()
                                ? number
                                : QString(",%1").arg(number));
            }
    }
    return promeni;
}
